//引入路由的npi
import ElementTest from '@/views/ElementTest.vue'
import ElementTest2 from '@/views/ElementTest2.vue'
import {createRouter,createWebHashHistory} from 'vue-router'
//引入页面
const Home = ()=> import('@/views/Home.vue')
const About = ()=> import('@/views/About.vue')
const NotFound =()=> import('@/views/404.vue')

// 引入用户中心
const userCenter = () => import('@/views/user-center/index.vue')
const userProfile = () => import('@/views/user-center/Profile.vue')
const userSettings = () => import('@/views/user-center/Setting.vue')
const ElemenPlus = () => import('@/views/ElementTest.vue')
const Login = () => import('@/views/Login.vue')
const ElemenPlus2 = () => import('@/views/ElementTest2.vue')


//配置路由配置
const routeConfig = [
    {
        path:'/home',
        component:Home,
        name:'home'
    },
    {
        path:'/about',
        component:About,
        name:'about'
    },
    {
      path:'/Login',
      component:Login,
      name:'login'
  },
    {
        path: '/:pathMatch(.*)*',
        name: 'not found',
        component: NotFound
      },  
      // 用户中心
      {
        path: '/user',
        name: 'user',
        component: userCenter,
        redirect: '/user/profile',
        children: [
          {
            path: 'profile',
            name: 'profile',
            component: userProfile
          },
          {
            path: 'settings',
            name: 'settings',
            component: userSettings
          },
        ]
      },
      {
        path:'/element',
        name:'element',
        component:ElementTest
      },
      {
        path:'/element2',
        name:'element2',
        component:ElementTest2
      },
     
    
    
]
//创建路由实例化对象 并对外暴露
const router = createRouter({
        history:createWebHashHistory(),
        routes:routeConfig
    })

    router.beforeEach((to, from) => {
        console.log('to', to);
        console.log('from', from);
      })
      
    router.afterEach((to, from) => {
        console.log('后置to', to);
        console.log('后置from', from);
      })
      


export default router